using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
using System.IO;
using for7raid.vkPlayer;

namespace ControlTemplates
{
    public partial class MinimazeWindow : ResourceDictionary
    {
        public MinimazeWindow()
        {
            InitializeComponent();
        }

        private bool isResizing = false;
        
        
        private void window_initiateResize(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isResizing = true;
        }
        

        private void window_endResize(object sender, System.Windows.Input.MouseEventArgs e)
        {
            isResizing = false;

            // Make sure capture is released.
            System.Windows.Controls.Primitives.ResizeGrip rect = (System.Windows.Controls.Primitives.ResizeGrip)sender;
            rect.ReleaseMouseCapture();
        }

        private void window_Resize(object sender, System.Windows.Input.MouseEventArgs e)
        {
            System.Windows.Controls.Primitives.ResizeGrip rect =(System.Windows.Controls.Primitives.ResizeGrip) sender;
            Window win = (Window)rect.TemplatedParent;

            if (isResizing)
            {                
                rect.CaptureMouse();
                /*if (resizeType == ResizeType.Width) */win.Width = e.GetPosition(win).X + 5;
                /*if (resizeType == ResizeType.Height) */win.Height = e.GetPosition(win).Y + 5;                 
            }            
        }

        private void titleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Window win = (Window)
                ((FrameworkElement)sender).TemplatedParent;
            win.DragMove();
            win.SaveSize();
        }

        private void cmdClose_Click(object sender, RoutedEventArgs e)
        {
            Window win = (Window)
                ((FrameworkElement)sender).TemplatedParent;
            win.Close();
        }

        private void cmdHide_Click(object sender, RoutedEventArgs e)
        {
            Window win = (Window)
                ((FrameworkElement)sender).TemplatedParent;
            win.WindowState = WindowState.Minimized;
        }

        private void cmdRestore_Click(object sender, RoutedEventArgs e)
        {
            Window win = (Window)
                ((FrameworkElement)sender).TemplatedParent;
            win.Template = Application.Current.FindResource("FullWindowControlTemplate") as ControlTemplate;
            win.ContentTemplate = Application.Current.FindResource("FullViewTemplate") as DataTemplate;
            win.SizeToContent = SizeToContent.Manual;
            //win.Height = 350D;
            //win.Width = 300D;
            win.SetSize();
        }
    }
}
